local xunshi = fk.CreateSkill {

  name = "joy__xunshi",

  tags = { Skill.Compulsory, },

}



xunshi:addEffect("filter", {
  name = "joy__xunshi",
  mute = true,
  frequency = Skill.Compulsory,
  card_filter = function(self,  card, player)
    return player:hasSkill(xunshi.name) and card.multiple_targets 
  end,
  view_as = function(self, player,card)
    return Fk:cloneCard("slash", Card.NoSuit, card.number)
  end,
})

xunshi:addEffect(fk.CardUsing, {
  name = "#joy__xunshi_trigger",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xunshi.name) and data.card.color == Card.NoColor
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, xunshi.name)
    player:broadcastSkillInvoke(xunshi.name)
    if player:getMark("xunshi") < 4 then
      player.room:addPlayerMark(player, "xunshi", 1)
    end
    local targets = data:getUseExtraTargets()
    local n = #targets
    if n == 0 then return false end
    local tos = room:askForChoosePlayers(player, targets, 1, n, "#xunshi-choose:::"..data.card:toLogString(), xunshi.name, true)
    if #tos > 0 then
      table.forEach(tos, function (id)
        table.insert(data.tos, {id})
      end)
    end
  end,
})

xunshi:addEffect("targetmod", {
  name = "#joy__xunshi_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return player:hasSkill(xunshi.name) and card and card.color == Card.NoColor
  end,
  bypass_distances =  function(self, player, skill, card)
    return player:hasSkill(xunshi.name) and card and card.color == Card.NoColor
  end,
})

return xunshi